<template>
  <div>
    <el-card class="box-card margin_30">
      <div slot="header" class="clearfix">
        <span>条件查询</span>
      </div>
      <el-form :model="orderInfo" label-width="80px" :inline="true" size="mini">
        <el-form-item label="订单编号">
          <el-input v-model="orderInfo.orderSn" placeholder="请填写订单编号" />
        </el-form-item>
        <el-form-item label="订单类型">
          <el-select v-model="orderInfo.orderType" placeholder="订单类型">
            <el-option
              label="正常订单"
              value="0"
            />
            <el-option
              label="秒杀订单"
              value="1"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="支付方式">
          <el-select v-model="orderInfo.payType" placeholder="支付方式">
            <el-option
              label="未支付"
              value="0"
            />
            <el-option
              label="支付宝"
              value="1"
            />
            <el-option
              label="微信"
              value="2"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-select v-model="orderInfo.status" placeholder="订单状态">
            <el-option
              label="待付款"
              value="0"
            />
            <el-option
              label="待发货"
              value="1"
            />
            <el-option
              label="已发货"
              value="2"
            />
            <el-option
              label="已完成"
              value="3"
            />
            <el-option
              label="退单"
              value="4"
            />
            <el-option
              label="无效订单"
              value="5"
            />
          </el-select>
        </el-form-item>
        <el-button size="mini" @click="reset">重置</el-button>
        <el-button size="mini" type="primary" @click="search">搜索</el-button>
      </el-form>
    </el-card>

    <el-card class="box-card margin_30">
      <div>
        <el-table
          :data="orderList"
          border
          style="width: 100%"
        >
          <el-table-column
            type="index"
            label="#"
            fixed="left"
            width="50"
            align="center"
          />
          <el-table-column
            prop="orderSn"
            label="订单编号"
            align="center"
            width="250"
          />
          <el-table-column
            prop="coverImg"
            label="支付方式"
            align="center"
            width="180"
          >
            <template slot-scope="scope">
              <el-button v-if="scope.row.payType == 0" size="small">
                未支付
              </el-button>
              <el-button v-else-if="scope.row.payType == 1" size="small">
                <svg-icon icon-class="alipay" class-name="custom-class" />
              </el-button>
              <el-button v-else size="small">
                <svg-icon icon-class="wx" class-name="custom-class" />
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            label="订单状态"
            width="180"
            align="center"
          >
            <template slot-scope="scope">
              <el-button v-if="scope.row.status == 0" type="danger" size="small">
                待付款
              </el-button>
              <el-button v-else-if="scope.row.status == 1" type="warning" size="small">
                待发货
              </el-button>
              <el-button v-if="scope.row.status == 2" type="primary" size="small">
                已发货
              </el-button>
              <el-button v-else-if="scope.row.status == 3" type="primary" plain size="small">
                已完成
              </el-button><el-button v-if="scope.row.status == 4" type="info" plain size="small">
                退货
              </el-button>
              <el-button v-else-if="scope.row.status == 5" type="info" size="small">
                无效订单
              </el-button>
            </template>
          </el-table-column>

          <el-table-column
            prop="createTime"
            label="添加时间"
            align="center"
            width="200"
          />

          <el-table-column
            prop="memberUsername"
            label="用户账号"
            align="center"
            width="200"
          />

          <el-table-column
            label="订单类型"
            align="center"
            width="200"
          >
            <template slot-scope="scope">
              <el-button v-if="scope.row.orderType == 0" size="small">
                正常订单
              </el-button>
              <el-button v-else-if="scope.row.orderType == 1" size="small">
                秒杀订单
              </el-button>
            </template>
          </el-table-column>

          <el-table-column
            prop="note"
            label="备注"
            align="center"
            width="200"
          />
          <el-table-column
            prop=""
            label="操作"
            fixed="right"
            align="center"
            width="150"
          >
            <template slot-scope="scope">
              <el-button icon="el-icon-view" type="primary" size="small" @click="goOrderDetail(scope.row.id)">查看订单</el-button>
            </template>

          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="start"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import {
  findOrdersByPage
} from '@/api/orderManage/orderList/index'
import mixins from '@/mixins/index'
export default {
  name: 'VueAdminTemplateMasterIndex',
  mixins: [mixins],
  data() {
    return {
      orderInfo: {
        'deliverySn': '',
        'id': '',
        'memberUsername': '',
        'orderSn': '',
        'orderType': '',
        'payType': '',
        'sourceType': '',
        'status': ''
      },
      orderList: []
    }
  },

  created() {
    this.init()
  },

  mounted() {

  },

  methods: {
    reset() {
      var obj = {
        'deliverySn': '',
        'id': '',
        'memberUsername': '',
        'orderSn': '',
        'orderType': '',
        'payType': '',
        'sourceType': '',
        'status': ''
      }
      this.orderInfo = obj
      // console.log(this.orderInfo)
    },
    goOrderDetail(id) {
      this.$router.push(`/orderManage/orderDetail/?id=${id}`)
    },

    search() {
      this.init()
    },
    init() {
      findOrdersByPage(this.start, this.limit, this.orderInfo).then(res => {
        console.log(res)
        this.orderList = res.data.rows
        this.total = res.data.total
      })
    }
  }
}
</script>

<style scoped>

</style>
